/**
 * @author caesar
 * @date 2025/7/1
 * @apiNote
 */
//求最值以及下标(元素重复和元素不重复的情况)
public class arrayMethodexercise4 {
    public static void main(String[] args) {
        /*
        方法一，考虑元素重复，遍历数组，将最大值保存在max中，并记录最大值的下标
        最后遍历数组，将所有等于max的元素下标打印出来。
        int[] arr =[8, 7, 5, 9, 9, 8];
        int max = arr[0];
        int index = 0;
        for (int i = 1; i < arr.length; i++) {
            if(arr[i]>max){
                max = arr[i];
                index = i;
            }
        }
        System.out.println("max = " + max);
        System.out.println("index = " + index);
        for (int i = 1; i < arr.length; i++) {
            if(arr[i]==max){
                System.out.print("," + i);
            }
        }
    */
        //方法二，使用字符串进行拼接，不需要多进行循环
        int[] arr = {8, 7, 5, 9, 9, 8};
        int max = arr[0];
        String index = "0";
        for (int i = 1; i < arr.length; i++) {
            if (arr[i] > max) {
                max = arr[i];
                index = i + " ";
            } else if (arr[i] == max) {
                index += "," + i;
            }
        }
        System.out.println("max = " + max);
        System.out.println("index = " + index);
    }
}
